<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var p = 2;
    function fn() {
      var p =3
      console.log(p)
    }
    fn(); // 3

    // 闭包
    function fn2() {
      var a = 12;
      function bar() {
        console.log(a)
      }
      return bar
    }   
    var f = fn2();
    console.log(f())
  </script>
</body>
</html>